<template>
  <div class="switch">
    <div
      v-for="item in data"
      :key="item.value"
      :class="['switch-item', item.value === activeName ? 'active' : '']"
      @click="change(item)"
    >
      {{ item.name }}
    </div>
  </div>
</template>

<script>
export default {
  name: 'SwitchTabs',
  model: {
    prop: 'activeName',
    event: 'change'
  },
  props: {
    activeName: String,
    data: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    change(item) {
      this.$emit('change', item.value)
    }
  }
}
</script>

<style scoped lang="scss">
.switch {
  margin-right: 30px;
  background: #F0F0F0;
  border-radius: 18px;
  display: flex;
  align-items: center;
  height: 36px;
  padding: 4px;
  .switch-item {
    margin: 4px;
    background-color: transparent;
    font-size: 14px;

    font-weight: 400;
    color: #999999;
    line-height: 22px;
    padding: 4px 16px;
    cursor: pointer;
  }
  .switch-item.active {
    background: #1AAD23;
    border-radius: 14px;
    color: #ffffff;
  }
}
</style>
